# Maintainer: Orhun Parmaksız <orhun@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Jake McGinty <jake@tonari.no>

pkgname=innernet
pkgver=1.5.5
pkgrel=1
pkgdesc="A private network system that uses WireGuard under the hood"
arch=('loong64' 'x86_64')
url="https://github.com/tonarino/innernet"
license=('MIT')
depends=('sqlite')
makedepends=('rust' 'git' 'clang' 'llvm')
source=("$url/archive/v$pkgver/$pkgname-$pkgver.tar.gz")
sha256sums=('b4b7f89658b3c8b77d6482e7a7d21362037fb1f332b9db53bebda6fd8f6b91ad')
options=('!lto')

prepare() {
  cd "$pkgname-$pkgver"
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd "$pkgname-$pkgver"
  cargo build --release --frozen
}

check() {
  cd "$pkgname-$pkgver"
  cargo test --frozen
}

package() {
  cd "$pkgname-$pkgver"

  install -Dm 755 "target/release/$pkgname" "$pkgdir/usr/bin/$pkgname"
  install -Dm 755 "target/release/$pkgname-server" "$pkgdir/usr/bin/$pkgname-server"

  install -Dm 644 "client/$pkgname@.service" "$pkgdir/usr/lib/systemd/system/$pkgname@.service"
  install -Dm 644 "client/$pkgname.target" "$pkgdir/usr/lib/systemd/system/$pkgname.target"

  install -Dm 644 "server/$pkgname-server@.service" "$pkgdir/usr/lib/systemd/system/$pkgname-server@.service"

  for binary in "$pkgname" "$pkgname-server"; do
    install -Dm 644 "doc/$binary.completions.bash" "$pkgdir/usr/share/bash-completion/completions/$binary"
    install -Dm 644 "doc/$binary.completions.fish" "$pkgdir/usr/share/fish/vendor_completions.d/$binary.fish"
    install -Dm 644 "doc/$binary.completions.zsh" "$pkgdir/usr/share/zsh/site-functions/_$binary"
    install -Dm 644 "doc/$binary.8.gz" "$pkgdir/usr/share/man/man8/$binary.8.gz"
  done

  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm 644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
}

# vim:set ts=2 sw=2 et:
